/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package bd;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JComboBox;

/**
 *
 * @author Ranieri
 */
public class opcoes extends JComboBox {

    public opcoes() {
        super();
    }

    public void mudaModel(ResultSet retorno) {
        try {
            this.setModel(constroiModel(retorno));
        } catch (SQLException ex) {
            Logger.getLogger(opcoes.class.getName()).log(Level.SEVERE, null, ex);
        }

    }

    private DefaultComboBoxModel constroiModel(ResultSet retorno) throws SQLException {
        ArrayList<Object> linhas = new ArrayList<Object>();
        while (retorno.next()) {
            linhas.add(retorno.getObject(1));
        }
        Object array[] = new Object[linhas.size()];
        for (int i = 0; i < linhas.size(); i++) {
            array[i] = linhas;
        }
        return new DefaultComboBoxModel(array);
    }
}
